package src.dual_pointers;

import java.util.HashSet;
import java.util.Set;

/**
 * @author starsea
 * @date 2024-08-21 15:10
 */

public class Test05 {
    public static void main(String[] args) {
        //String str="bbbbb";
        //int c=lengthOfLongestSubstring(str);
        //int[] arr={1,1,0,1,1,1};
        //int c=lengthOfLongestSubstring()

    }

    public static int lengthOfLongestSubstring(String s) {
        char[] arr=s.toCharArray();
        int n=arr.length;
        int left=0;
        int right=0;
        int ans=0;
        Set<Character> set=new HashSet<>();
        while(left<=right)
        {
            while( right<n && !set.contains(arr[right]))
            {

                set.add(arr[right++]);
                ans=ans>right-left?ans:right-left;
            }
            if(right>=n)
            {
                break;
            }
            while( left<right && set.contains(arr[right]))
            {
                set.remove(arr[left++]);
            }

        }
        return ans;
    }
}
